<#include '/admin/header.html' >


<script src="${ctx}/shop/admin/statistics/member/js/add_member_num.js" type="text/javascript" ></script>
<style>
	.datagrid-sort-asc .datagrid-sort-icon{display:none}
</style>
<div class="main">
	<!-- 搜索框 -->
	<div style="display: block;" class="searchAdvanced">
		<table width="98%" border="0" cellspacing="0" cellpadding="8">
			<tr>
				<td width="80">
					按订单周期：
				</td>
				<td width="70" >
					<select id="cycle_type">
						<!-- <option value="0">--请选择--</option> -->
						<option value="1">按照月统计</option>
						<option value="2">按照年统计</option>
					</select>
				</td>
				<td width="70" >
					<select id="year">
						<option value="0">--全年--</option>
					</select>
				</td>
				<td width="70" >
					<select id="month">
						<!-- <option value="0">--请选择--</option> -->
					</select>
				</td>
				
				<td width="200" style="text-align: center;float: right">
					<a id="search_statis" class="button blueButton"  href="javascript:void(0);">开始搜索</a>
				</td>
				<td></td>
		</table>
	</div>
	<div class="clear height10"></div>
	
	<!-- 主体 -->
	<div class="input">
		<div style="display: block;" class="goods_input">
		
		<!-- 统计图div -->
		<div id="order_num_statistics">
			
		</div>
		<div class="tableDiv">
			<!-- dataGrid -->
			<table id="order_num_dg" class="easyui-datagrid"  data-options="pagination:false,rownumbers:true, fitColumns:'true',sortName:'membertime'" >
				<thead>
					<tr>
						<th data-options="field:'membertime',width:150" >日期/月</th>
						<th data-options="field:'member_num',width:150" >本月/年</th>
						<th data-options="field:'last_member_num',width:150" >上月/年</th>
						<th data-options="field:'member_an',width:150" >同比</th>
					</tr>
				</thead>
				
			</table>
		</div> 
		
		</div>
	</div>	
	<div class="clear height10"></div>
</div>
<script type="text/javascript">
//初始化下拉菜单中的时间
var currentYear = new Date().getFullYear();
var historyYear = currentYear-10;
var currentmonth = new Date().getMonth();
currentmonth+=1;

//for循环得到年数
for(var i=0;i<20;i++){
	
	//选中当前年
	if(currentYear==historyYear){
		$("#year").append("<option value='"+historyYear+"' selected >"+historyYear+"年</option>" );
	}else{
		$("#year").append("<option value='"+historyYear+"' >"+historyYear+"年</option>" );
	}
	historyYear++;
}

//for循环得到月份
for(var i=1;i<=12;i++){
	
	// 选中当前月
	if(currentmonth==i){
		$("#month").append("<option value='"+i+"' selected >"+i+"月</option>" );
	}else{
		$("#month").append("<option value='"+i+"' >"+i+"月</option>" );
	}
}

/**
 * 获取日期条件
 * @return dateWhere[] 下标0=开始时间  下标1=结束时间
 */
function getDateWhere(){
	
	var c_type = $("#cycle_type").val();
	var startDate, endDate; //开始时间和结束时间
	
	if (c_type == 0) {
		alert("请先选择查询方式!");
		return;
	}
	
	//如果是按照年来筛选订单的
	if(c_type == 2) {
		
		var year = $("#year").val();
		
		if(year == 0) {
			var dateWhere = [];
			dateWhere[0] = "";
			dateWhere[1] = "";
			return dateWhere;
		}
		
		startDate = year + "-01-01 00:00:01";
		endDate = year + "-12-31 23:59:59";
		
	} else {
		
		var year = parseInt($("#year").val());
		var month = parseInt($("#month").val());

		if(year == 0) {
			alert("请选择年份");
			return;
		}
		if(month == 0) {
			alert("请选择月份");
			return;
		}
		
		//得到一个月最后一天
		var lastDate = new Date(year, month, 0);
		var lastDay = lastDate.getDate();
		
		startDate = year + "-" + month + "-01 00:00:01";
		endDate = year + "-" + month + "-" + lastDay +" 23:59:59";
	}
	var dateWhere = [];
	dateWhere[0] = startDate;
	dateWhere[1] = endDate;
	dateWhere[2] = c_type;
	return dateWhere;
}



/**
 * 获取上月日期条件
 * @return dateWhere[] 下标0=开始时间  下标1=结束时间
 */
function getLastDateWhere(){
	
	var c_type = $("#cycle_type").val();
	var lastStartDate, lastEndDate; //开始时间和结束时间
	if (c_type == 0) {
		alert("请先选择查询方式!");
		return;
	}
	
	//如果是按照年来筛选订单的
	if(c_type == 2) {
		
		var lastYear = parseInt($("#year").val())-parseInt(1);
		
		if(lastYear == 0) {
			var lastDateWhere = [];
			lastDateWhere[0] = "";
			lastDateWhere[1] = "";
			return lastDateWhere;
		}
		
		lastStartDate = lastYear + "-01-01 00:00:01";
		lastEndDate = lastYear + "-12-31 23:59:59";
		
		
	} else {
		
		var year = parseInt($("#year").val());
		var lastMonth = parseInt($("#month").val())-parseInt(1);
		
		//如果是1月，得到上一年12月的数据
		if(lastMonth==0){
			var lastYear = parseInt($("#year").val())-parseInt(1);
			lastStartDate = lastYear + "-12-01 00:00:01";
			lastEndDate = lastYear + "-12-31 23:59:59";
			
		}
		
		//如果是1月，得到上一年12月的数据
		if(lastMonth!=0){
			//得到一个月最后一天
			var lastDate = new Date(year, lastMonth, 0);
			var lastDay = lastDate.getDate();
			lastStartDate = year + "-" + lastMonth + "-01 00:00:01";
			lastEndDate = year + "-" + lastMonth + "-" + lastDay +" 23:59:59";
		}
		
	}
	var lastDateWhere = [];
	lastDateWhere[0] = lastStartDate;
	lastDateWhere[1] = lastEndDate;
	return lastDateWhere;
}





/**
 * 初始化柱状图
 * @param id	html 初始化div的id
 * @param conf	相关配置
 */
function initHistogram(id,conf){
	
	var options = {
			credits: {
	             //text: 'Javashop',
	             //href: 'http://www.javamall.com.cn'
				enabled:false
	        },
			
	        title : {
				text : conf.title
			},
			xAxis : {
				categories : conf.categories
			},
			yAxis : {
				min : 0,
				title : {
					text : conf.yDesc
				}
			},
			series : conf.series
		};
	$("#" + id).highcharts(options);
};

//搜索点击事件
$("#search_statis").click(function(){
	
	// 1.获取时间条件
	var dateWhere = getDateWhere();
	var lastDateWhere = getLastDateWhere();
	addMenber.addMenberJson();

});
</script>
<#include '/admin/footer.html' >